package com.gs.disk.rabbitmq.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/simple")
@Slf4j
public class SimpleProducer {

    private static final String QUEUE_NAME="gs.simple.queue";

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage/{message}")
    public String send(@PathVariable("message")String message){
        log.info("准备发送消息:"+message);
        rabbitTemplate.convertAndSend(QUEUE_NAME,message.getBytes());
        return "消息已经发送成功";
    }

    @GetMapping("/sendVerify/{emailCount}")
    public String sendVerify(@PathVariable("emailCount")String emailCount) {
        log.info("准备发送消息email: " + emailCount);

        String msg = "gs.sendEmailVerify:" + emailCount;
        rabbitTemplate.convertAndSend(QUEUE_NAME,msg.getBytes());
        return "消息已经发送成功";
    }
}


